/**
 * Created by Teddy on 16/1/5.
 */

$(function () {
    /*Init editable table*/
    $('#ServerTable').editable();
    $('#UserTable').editable();
});

function actionFormatter(value, row, index) {
    return [
        /*Update*/
        '<a class="edit ml10" href="javascript:void(0)" title="Edit">',
        '<i class="glyphicon glyphicon-ok-circle"></i>',
        '</a>',
        /*Delete*/
        '<a class="remove ml10" href="javascript:void(0)" title="Remove">',
        '<i class="glyphicon glyphicon-remove-circle"></i>',
        '</a>'
    ].join('');
}


window.actionEventsServer = {
    /*Update*/
    'click .edit': function (e, value, row, index) {
        $.ajax({
            type: "POST",
            url: "updateTestServer.php",
            data: row,
            success: function(data) {
                if(data == "1"){
                    alert ("Update Success!");
                }
                else {
                    alert ("Update Failed!")
                }
            }
        });
        /*For Debug*/
        /*alert('You click edit icon, row: ' + JSON.stringify(row));
        console.log(value, row, index);*/
    },
    /*Delete*/
    'click .remove': function (e, value, row, index) {
        alert('You will remove, row: ' + JSON.stringify(row));
    }
};

window.actionEventsUser = {
    /*Update*/
    'click .edit': function (e, value, row, index) {
        $.ajax({
            type: "POST",
            url: "updateTestUser.php",
            data: row,
            success: function(data) {
                if(data == "1"){
                    alert ("Update Success!");
                }
            }
        });
        /*For Debug*/
        /*alert('You click edit icon, row: ' + JSON.stringify(row));
         console.log(value, row, index);*/
    },
    /*Delete*/
    'click .remove': function (e, value, row, index) {
     alert('You will remove, row: ' + JSON.stringify(row));
     }
};
